package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.bean.GonggaoBean
import com.erp.R
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_gonggao_item.view.*

/**
 * Created by Administrator on 2017/1/10/010.
 * 作者：刘洋
 */
class GonggaoAdapter(context: Context, private var mlist: List<GonggaoBean>, private val mtime: Long) : BaseAdapter() {
    private val minfalter: LayoutInflater = LayoutInflater.from(context)

    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var v: View
        var vh: ViewHolder
        if (convertView == null) {
            v = minfalter.inflate(R.layout.lv_gonggao_item, null)
            vh = ViewHolder(v)
            v.tag = vh
        } else {
            v = convertView
            vh = convertView.tag as ViewHolder
        }
        var gonggaoBean = mlist[position]
        vh.TvTitle.text = gonggaoBean.title
        vh.TvType.text = gonggaoBean.type_name
        vh.TvTime.text = Myutil.getdata(gonggaoBean.field_notice_board_time_value)
        vh.TvGengxin.text = Myutil.getdata(gonggaoBean.changed)
        if (gonggaoBean.changed.matches("[0-9]+".toRegex())) {
            if (mtime - java.lang.Long.valueOf(gonggaoBean.changed) > 259200) {
                vh.IvNew.visibility = View.GONE
            } else {
                vh.IvNew.visibility = View.VISIBLE
            }
        }
        return v
    }

    fun Allnoti(list: List<GonggaoBean>) {
        this.mlist = list
        notifyDataSetChanged()
    }

    class ViewHolder(v: View) {
        var TvTitle = v.TvGonggaoTitle
        var IvNew = v.IvGonggaoNew
        var TvType = v.TvGonggaoType
        var TvTime = v.TvGonggaoTime
        var TvGengxin = v.TvGonggaoGengxin
    }
}
